package com.charity.mapper;

import com.charity.pojo.User;
import org.apache.ibatis.annotations.*;

import java.util.List;

@Mapper
public interface UserMapper {

    @Select("select * from user where userName=#{userName} and password=#{password}")
    User user(String userName, String password);

    @Insert("insert into user(userName, password, role, realName, sex, idCard, account, phone, email, address, difficultyType, createDate)" +
            "values(#{userName}, #{password}, #{role}, #{realName}, #{sex}, #{idCard}, #{account}, #{phone}, #{email}, #{address}, #{difficultyType}, #{createDate})")
    Integer addUser(String userName, String password, String role, String realName, String sex, String idCard, String account, String phone,
                    String email, String address, String difficultyType, String createDate);

    @Select("select id from user where userName=#{userName}")
    Long userId(String userName);

    @Select("select * from user where id=#{id}")
    User userById(Long id);

    @Update("update user set userName=#{userName}, password=#{password}, realName=#{realName}, sex=#{sex}, idCard=#{idCard}, " +
            "account=#{account}, phone=#{phone}, email=#{email}, address=#{address}, difficultyType=#{difficultyType} where id = #{id}")
    Integer updateUser(Long id, String userName, String password, String realName, String sex, String idCard, String account, String phone,
                       String email, String address, String difficultyType);

    @Delete("delete from user where id = #{id}")
    Integer deleteUser(Long id);

    @Select("select * from user where role='受助者'")
    List<User> userBySZ();

}
